// json 数据渲染
const List = document.querySelectorAll('.nav .data')
var val; // 初始化渲染内容

Data.forEach((item, index) => {
  val += ' <li><div class="icon"> <img src="' + item.icon + '" alt="" />  </div> <div class="text">' + item.val + '</div></li>'
})
// 截取 undefined
val = val.slice(9)
console.log(val);
// 渲染数据
List[0].innerHTML = val


// 倒计时
const time = document.querySelector('.time');
const hh = time.children[0];
const mm = time.children[1];
const ss = time.children[2];
var inputTime = +new Date('2023-1-10 22:00:00'); // 返回的是用户输入时间总的毫秒数
countDown();  // 打开页面即开始调用
setInterval(countDown, 1000); // 1s后继续调用
function countDown() {
  var nowTime = +new Date();
  var times = (inputTime - nowTime) / 1000;
  var h = parseInt(times / 60 / 60 % 24);
  h = h < 10 ? '0' + h : h;
  hh.innerHTML = h;
  var m = parseInt(times / 60 % 60);
  m = m < 10 ? '0' + m : m;
  mm.innerHTML = m;
  var s = parseInt(times % 60);
  s = s < 10 ? '0' + s : s;
  ss.innerHTML = s;
}

// tab切换 
const tabBox = document.querySelectorAll('.tabBox li')

const tabBox_item = document.querySelectorAll('.tabBox_item')

const textColor = document.querySelectorAll('.tabBox .a2')
tabBox_item[0].style.display = 'block'
for (let i = 0; i < tabBox.length; i++) {

  let index = i
  tabBox[i].addEventListener('click', function () {

    console.log(textColor);
    for (let t = 0; t < tabBox.length; t++) {
      tabBox[t].className = ''
      tabBox_item[t].style.display = 'none'
      textColor[t].style.color = ''
    }
    this.className = 'active'
    tabBox_item[index].style.display = 'block'
    textColor[index].style.color = 'rgb(255, 145, 0)'
  })

}


// 返回顶部
const returnTop = document.querySelector('.returntop')

returnTop.addEventListener('click', function () {

  // 添加动画 由快到慢
  scrollToptimer = setInterval(function () {
    console.log("定时循环回到顶部")
    var top = document.body.scrollTop || document.documentElement.scrollTop;
    var speed = top / 4;
    if (document.body.scrollTop != 0) {
      document.body.scrollTop -= speed;
    } else {
      document.documentElement.scrollTop -= speed;
    }
    if (top == 0) {
      clearInterval(scrollToptimer);
    }
  }, 30)
})
